package cn.le.handler;

import cn.le.netty.cient.NettyClient;
import cn.le.netty.inf.NettyHandler;
import cn.le.netty.util.ConnectionUtil;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.stereotype.Component;

@Component
@ChannelHandler.Sharable
public class InactiveHandler extends ChannelInboundHandlerAdapter implements NettyHandler {

    /**
     * 链接不活跃时触发
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        if (ctx.channel().isActive()){  //判断链接是否中断
            ctx.fireChannelInactive();
            return;
        }
        //退出服务器器
        ConnectionUtil.exit("192.168.0.86",1111);
        //重新登录
        NettyClient.login("192.168.0.86",1111,1);
    }
}
